package com.wicket.okrdataassets.base.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wicket.okrdataassets.base.service.MOmsResourceEviRecordService;
import com.wicket.okrdataassets.base.service.dto.req.*;
import com.wicket.okrdataassets.common.dto.FieldInfo;
import com.wicket.okrdataassets.common.exception.BizException;
import com.wicket.okrdataassets.common.tools.StringUtils;
import com.wicket.okrdataassets.common.util.CommonFunctionHelper;
import com.wicket.okrdataassets.dal.mapper.mbg.OmsResourceEviRecordMapper;
import com.wicket.okrdataassets.dal.po.mbg.OmsResourceEviRecord;
import java.lang.reflect.Field;
import java.util.*;
import java.util.ArrayList;
import java.util.stream.Collectors;
//import com.wicket.okrdataassets.base.service.dto.res.*;

import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author ：
 * @since 2022/1/19 15:39
 *
 * 
 * @version 1.0
 */
@Service
public class MOmsResourceEviRecordServiceImpl
  extends ServiceImpl<OmsResourceEviRecordMapper, OmsResourceEviRecord>
  implements MOmsResourceEviRecordService {

  @Autowired
  OmsResourceEviRecordMapper omsResourceEviRecordMapper;
/**
   * 8-01-02-新增存证记录[10303]
   * gen by moon at 11/11/2024, 1:24:43 AM
   */
 @Trace(operationName = "8-01-02-新增存证记录")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  String  addEviRecord(OmsResourceEviRecord omsResourceEviRecord) {
     omsResourceEviRecord.setEviRecordId(CommonFunctionHelper.getUid());//DISTRIBUTED_ID
omsResourceEviRecord.setCreateInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//CURRENT_INDUCTIONID
omsResourceEviRecord.setCreateTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME
omsResourceEviRecord.setSpaceId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID
omsResourceEviRecord.setAppId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecAppId());//CURRENT_APPID
     if(super.save(omsResourceEviRecord)){
        return omsResourceEviRecord.getEviRecordId();
     }else {
        return "-1";
     }
    
  }
/**
   * 8-01-02查询存证记录详情[10304]
   * gen by moon at 11/11/2024, 1:24:46 AM
   */
 @Trace(operationName = "8-01-02查询存证记录详情")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  OmsResourceEviRecord  queryEviRecordDetail(QueryEviRecordDetailReq reqDto) {
     
        try {
         reqDto.setSpaceId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID
            QueryWrapper<OmsResourceEviRecord> queryWrapper = new QueryWrapper<>();
            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap, new ArrayList<>());
            queryWrapper.orderByDesc("create_time");
            List<OmsResourceEviRecord> retList = super.list(queryWrapper);
            if(retList!=null && retList.size()>0){
                OmsResourceEviRecord retData = retList.get(0);
                
                return retData;
            }
            return null;
      } catch (Exception e) {
          e.printStackTrace();
          throw new BizException("-1",e,false);
      }
  }
}
